/**
 * 
 */
package epsofts.Neutron;

import java.util.Random;

/**
 * @author Pierre ESCALLIER
 * 
 */
public class EvalueurNbLibertes implements IEvalueur
{

	public static final String	LABEL						= "(Nb libertes)";
	public static final Boolean	ENABLED						= true;
	
	private static final Random random = new Random();
	
	private float m_resultat = 0;
	private short m_pos = 0;
	private short m_nb_mouvements = 0;
	private short m_score_base = 0;
	private short[] m_mouvements = null;
	private eCase[] m_cases = null;
	private short i;	
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see Neutron.IEvalueur#evalueurPlateau(Neutron.Plateau)
	 */
	public float evalueurPlateau(final Plateau i_plateau)
	{
		// TODO : Faire une seconde version qui tient compte du NEUTRON !!!
		m_resultat = 0;		
		m_cases = i_plateau.getCases();
		
		// Test des billes
		for(m_pos=0; m_pos < 25; ++m_pos)
		{
			if ((m_cases[m_pos] != eCase.VIDE) && (m_cases[m_pos] != eCase.NEUTRON))
			{
				m_nb_mouvements = 0;
				m_mouvements = i_plateau.listerCoupsBille(m_pos);
				for(i=0; i < 8; ++i)
				{
					if (m_mouvements[i] != m_pos) ++m_nb_mouvements;
				}
				
				m_score_base = (short) (m_nb_mouvements * 100);
				if (m_cases[m_pos] == eCase.ROUGE)
				{
					m_resultat += (m_score_base + random.nextInt(100));
				}
				else if (m_cases[m_pos] == eCase.BLEUE)
				{
					m_resultat -= (m_score_base + random.nextInt(100));
				}
			}
		}
		
		return m_resultat;
	}
}
